home *** CD-ROM | disk | FTP | other *** search
/ CD Ware Multimedia 1995 May / cd Ware (Juegos) Epimundo.iso / WIN / VB_TOOLS / SNIPPIT.ZIP / SNIPPITS.MDB / Snippits.json
Encoding:
JavaScript Object Notation  |  1993-12-15  |  7.9 KB

  1. {
  2.     "schema": {
  3.         "Description": "Memo/Hyperlink (255)",
  4.         "Snippit": "Memo/Hyperlink (255)"
  5.     },
  6.     "data": [
  7.         {
  8.             "Description": "CPicListBox Show Bitmaps and Text in a Listbox",
  9.             "Snippit": "// Used to store Bitmaps with Captions to display in list box\r\nclass CBitmapCaption\r\n{\r\npublic:\r\n\tCBitmap m_Bitmap[25];\r\n\tCString m_Caption[25];\r\n};\r\n\r\n// CPicListBox (The actual listbox on the CPicListBoxWnd parent window)\r\nclass CPicListBox : public CListBox\r\n{\r\npublic:\r\n\tCPicListBox(CWnd* pParent);\r\n};\r\n\r\n/////////////////////////////////////////////////////////////////////////////\r\n// CPicListBoxWnd window\r\nclass CPicListBoxWnd : public CWnd\r\n{\r\npublic:\r\n\tCPicListBoxWnd(CWnd*);\r\n    virtual \t\t~CPicListBoxWnd();\r\n    void \t\t\tAddItem(CString, CString);\r\n    CPicListBox*\tm_pLB_LIST;\r\nprivate:\r\n\tCBitmapCaption \tm_ListItem;\r\n\tint\t\t\t\tm_nListCount;\t\t// Count of Items in List\r\n\tint\t\t\t\tm_nItemSpacing;\t\t// Distance Items should be seperated by in listbox\r\n\tint\t\t\t\tm_nOffsetY;\t\t\t// Distance to place bitmap from top of rect for each item in list\r\n\tHFONT\t\t\tm_ListFont;\t\t\t// Font to be used in listbox\r\nprotected:\r\n\t//{{AFX_MSG(CPicListBoxWnd)\r\n\tafx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);\r\n\tafx_msg void OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct);\r\n\tafx_msg void OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct);\r\n\tafx_msg void OnDblclkList();\r\n\t//}}AFX_MSG\r\n\tDECLARE_MESSAGE_MAP()\r\n};\r\n\r\n/*\tCPicListBoxWnd is a parent window for a list box that displays Bitmap Images and Text.\r\n\tThe Bitmaps should be 48 x 100. The x axis (100) is variable and can be changed\r\n\tto almost any number without bad side effects. The y axis (48) can be changed\r\n\tbut you will need to adjust the m_nItemSpacing in the InitDialog\r\n\tSet m_ItemSpacing to Bitmap Height + 20. This will allow enough\r\n\tclearance for the rectangle that is drawn when an item is selected (Assuming you\r\n\tare using the Arial 8 pt. font). m_nOffsetY determines the amount of space to leave\r\n\tblank at the top of each list item. The actual listbox control is in a class called\r\n\tCPicListBox which is an owner draw listbox derived from CListBox. This is called in the\r\n\tconstructor of CPicListBoxWnd. A Listbox sends messages to its parent window only. This is\r\n\tthe reason for CPicListBoxWnd's existance.\r\n\r\n\tCode By: Todd Osborne\t12/14/93\r\n*/\r\n\r\n#include <afxwin.h>\r\n#include <afxext.h>\r\n#include \"piclistb.h\"\r\n\r\n#ifdef _DEBUG\r\n#undef THIS_FILE\r\nstatic char BASED_CODE THIS_FILE[] = __FILE__;\r\n#endif\r\n\r\n/////////////////////////////////////////////////////////////////////////////\r\n// CPicListBoxWnd\r\nCPicListBoxWnd::CPicListBoxWnd(CWnd* pParent)\r\n{\r\n\tCRect Prect;\r\n\tpParent->GetClientRect(&Prect);\r\n\t\r\n\tCRect rect(0, 0, 150, Prect.Height());\r\n\tCreate(NULL, \"\", WS_CHILD | WS_VISIBLE, rect, pParent, 5000, NULL);\r\n\t\r\n\t// Set Variables needed for drawing list box (See Notes above and in .h file)\r\n\tm_nListCount = 0;\r\n\tm_nOffsetY = 13;\r\n\tm_nItemSpacing = 78;\r\n\t\r\n\t// Create the actual List Box\r\n\tm_pLB_LIST= new CPicListBox(this);\r\n\t\r\n\t// Add Item(s) to List Box\r\n\tAddItem(\"A\", \"Test 0\");\r\n\tAddItem(\"B\", \"Test 1\");\r\n\tAddItem(\"C\", \"Test 2\");\r\n\tAddItem(\"D\", \"Test 3\");\r\n\tAddItem(\"E\", \"Test 4\");\r\n}\r\n\r\nCPicListBoxWnd::~CPicListBoxWnd()\r\n{\r\n\tdelete m_pLB_LIST;\r\n}\r\n\r\nvoid CPicListBoxWnd::AddItem(CString szBitmapName, CString szCaption)\r\n{\r\n\t// szBitampName: \t\tString name of bitmap in resource file\r\n\t// szCaption:\t\t\tString to be displayed to right of bitmap in list\r\n\tif ( m_nListCount<=24 )\r\n\t\t{\r\n\t\tm_ListItem.m_Bitmap[m_nListCount].LoadBitmap(szBitmapName);\r\n\t\tm_ListItem.m_Caption[m_nListCount] = szCaption;\r\n\t\tm_pLB_LIST->AddString((LPCSTR)&m_ListItem.m_Bitmap[this->m_nListCount]);\r\n\t\tthis->m_nListCount++;\r\n\t\t}\r\n}\r\n\r\nBEGIN_MESSAGE_MAP(CPicListBoxWnd, CWnd)\r\n\t//{{AFX_MSG_MAP(CPicListBoxWnd)\r\n\tON_WM_CREATE()\r\n\tON_WM_DRAWITEM()\r\n\tON_WM_MEASUREITEM()\r\n\tON_LBN_DBLCLK(5001, OnDblclkList)\r\n\t//}}AFX_MSG_MAP\r\nEND_MESSAGE_MAP()\r\n\r\n/////////////////////////////////////////////////////////////////////////////\r\n// CPicListBoxWnd message handlers\r\nint CPicListBoxWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)\r\n{\r\n\tif (CWnd::OnCreate(lpCreateStruct) == -1)\r\n\t\treturn -1;\r\n\t\r\n\t// Font to be used in List Box\r\n\tm_ListFont = CreateFont(14, 0, 0, 0, FW_MEDIUM, 0, 0, 0, ANSI_CHARSET, OUT_STROKE_PRECIS,\tCLIP_STROKE_PRECIS,\tDEFAULT_QUALITY, FF_SWISS | FF_DONTCARE, \"Arial\" );\r\n\t\r\n\treturn 0;\r\n}\r\n\r\nvoid CPicListBoxWnd::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)\r\n{\r\n\tCDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);\r\n\t\t\r\n\tif ((lpDrawItemStruct->itemState & ODS_SELECTED) && (lpDrawItemStruct->itemAction & (ODA_SELECT | ODA_DRAWENTIRE)))\r\n\t{\r\n\t\t// item has been selected - hilite frame\r\n\t\tCBrush Brush(GetSysColor(COLOR_HIGHLIGHT));\r\n\t\tpDC->FillRect(&lpDrawItemStruct->rcItem, &Brush);\r\n\t\tBrush.DeleteObject();\r\n\t}\r\n\r\n\tif (!(lpDrawItemStruct->itemState & ODS_SELECTED) && (lpDrawItemStruct->itemAction & ODA_SELECT))\r\n\t{\r\n\t\t// Item has been de-selected -- remove frame\r\n\t\tCBrush Brush(pDC->GetBkColor());\r\n\t\tpDC->FillRect(&lpDrawItemStruct->rcItem, &Brush);\r\n\t\tBrush.DeleteObject();\r\n\t}\r\n\t\r\n\t// Draw the bitmap (Bitmap will be centered left<>right in list box\r\n\tCDC MemDC;\r\n\tMemDC.CreateCompatibleDC (pDC);\r\n\tMemDC.SelectObject((CBitmap*)lpDrawItemStruct->itemData);\r\n\t\r\n\tCBitmap* pBitmap = (CBitmap*)lpDrawItemStruct->itemData;\r\n\tBITMAP Bitmap;\r\n\tpBitmap->GetObject(sizeof(Bitmap), &Bitmap);\r\n\t    \r\n\tpDC->BitBlt ( ((lpDrawItemStruct->rcItem.right - lpDrawItemStruct->rcItem.left) / 2) - Bitmap.bmWidth /  2,\r\n\t   \t\t\t    lpDrawItemStruct->rcItem.top + m_nOffsetY,\r\n\t   \t\t\t    lpDrawItemStruct->rcItem.right,\r\n\t   \t\t\t    lpDrawItemStruct->rcItem.bottom,\r\n\t   \t\t\t    &MemDC, 0, 0, SRCCOPY);\r\n\t\t\r\n\t// Determine which item is being added by looking at the rectangle (position).\r\n\t// Add appropriate caption string\r\n\tint ItemNum = (lpDrawItemStruct->rcItem.top / m_nItemSpacing);\r\n\t\r\n\t// Select which colors to use for text depending on itemState\r\n\tif (lpDrawItemStruct->itemState & ODS_SELECTED)\r\n\t\t{\r\n\t\t// Item is Selected\r\n\t\tpDC->SetBkColor(GetSysColor(COLOR_HIGHLIGHT));\r\n\t\tpDC->SetTextColor(GetSysColor(COLOR_HIGHLIGHTTEXT));\r\n\t\t}\r\n\telse\r\n\t\t{\r\n\t\t// Item is De-Selected\r\n\t\tpDC->SetBkColor(GetSysColor(COLOR_WINDOW));\r\n\t\tpDC->SetTextColor(GetSysColor(COLOR_WINDOWTEXT));\r\n\t\t}\r\n\t\t\r\n\t// Select the font for the list box and draw the text (m_Caption)\r\n\tCFont* pOldFont = pDC->SelectObject(CFont::FromHandle(m_ListFont));\r\n\t\r\n\tpDC->DrawText(m_ListItem.m_Caption[ItemNum],\r\n\t\t\t\t  m_ListItem.m_Caption[ItemNum].GetLength(),\r\n\t\t\t\t  &lpDrawItemStruct->rcItem,\r\n\t\t\t\t  DT_BOTTOM | DT_CENTER | DT_SINGLELINE);\r\n\t\t\r\n\t// Good Measures\r\n\tpDC->SelectObject(pOldFont);\r\n\tpOldFont->DeleteObject();\r\n\tReleaseDC(pDC);\r\n}\r\n\r\nvoid CPicListBoxWnd::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct)\r\n{\r\n\tlpMeasureItemStruct->itemHeight = m_nItemSpacing;\r\n}\r\n\r\nvoid CPicListBoxWnd::OnDblclkList()\r\n{\r\n\t// Double Clicked In The List\r\n\tint ListItem = m_pLB_LIST->GetCurSel();\r\n\r\n\t// Send Notification Message to handler\r\n\tMessageBox(\"Clicked in List Box\", \"Test\", MB_OK);\r\n}\r\n\r\nCPicListBox::CPicListBox(CWnd* pParent)\r\n{\r\n\tCRect Prect;\r\n\tpParent->GetClientRect(&Prect);\r\n\t\r\n\tCRect rect(Prect.left, Prect.top, Prect.Width()-1, Prect.Height());\r\n\tCreate(LBS_OWNERDRAWVARIABLE | LBS_NOTIFY | LBS_DISABLENOSCROLL | WS_VSCROLL | WS_CHILD | WS_VISIBLE | WS_BORDER, rect, pParent, 5001);\r\n}\r\n"
  10.         }
  11.     ]
  12. }